<?php
session_start();
include_once "../modele/DB.php";

if (isset($_GET['name']) && isset($_GET['toppings']) && isset($_GET['size']) && isset($_GET['isScore']) && isset($_GET['type'])) {
	$name = $_GET['name'];
	$toppings = explode(',', $_GET['toppings']);
	$size = $_GET['size'];
	$isScore = $_GET['isScore'];
	$type = $_GET['type'];
	
	$payementType = 0;
	if ($isScore == "Score") {
		$payementType = 1;
	}
	$orderId = -1;
	if(!isset($_SESSION['order_id']) || $_SESSION['order_id'] == -1){
		$orderId = dbAdd("`order`", "user_id, payment, address_id, telephone_id, payement_type, ended", "0, 12345, 0, 0, '$isScore', 0");
		$_SESSION['order_id'] = $orderId;
	}
	$orderItemId = dbAdd("order_item", "order_id, type, name_or_id, size, quantity, score", "'$_SESSION[order_id]', '$type', '$name', '$size', '1', '$payementType'");

	foreach($toppings as $topping) {
		$info =  explode('/', $topping);
		$name = $info[0];
		$quantity = $info[1];
		$position = $info[2];
		dbAdd("order_topping", "order_item_id, topping_name, quantity, position", "'$orderItemId', '$name', '$quantity', '$position'");
	}
}
?>